<?php 
	include ('lib/twitese.php');
	$title = "评论";
	include ('inc/header.php');
	
	if (!isLogin()) header('location: login.php');
?>

<script type="text/javascript" src="js/comments.js"></script>

<div id="statuses">
	<div class="weibo_ptWrapPdd">
		<?php 
			$p = 1;
			if (isset($_GET['p'])) {
				$p = (int) $_GET['p'];
				if ($p <= 0) $p = 1;
			}
			
			$type = isset($_GET['t'])? $_GET['t'] : 1;
			$t = getTwitter();
			switch ($type) {
				case 1:
					$statuses = $t->commentsTimeline($p);
					break;
				case 2:
					$statuses = $t->commentsByMe($p);
					break;
				default:
					$statuses = $t->commentsTimeline($p);
					break;
			}
			testResult($statuses);
			
			
			$empty = count($statuses) == 0? true: false;
			if ($empty) {
				tpEmpty();
			} else {
		?>
		
		<div id="subnav">
		<?php if ($type == 1) {?>
			<span class="subnavNormal">最新评论</span><span class="subnavLink"><a href="comments.php?t=2">发出的评论</a></span>
		<?php } else if ($type == 2) {?>
			<span class="subnavLink"><a href="comments.php?t=1">最新评论</a></span><span class="subnavNormal">发出的评论</span>
		<?php } ?>
		</div>
		
		<div id="info_head">
		</div>
		<div class="clear"></div>
	</div>
	
	<div class="weibo_postList">
		<?php 
			$output = '<ol class="timeline">';
			foreach ($statuses as $status) {
				$is_rt = isset($status->retweeted_status);
				
				$username = getEncryptCookie('twitese_name');
				
				$status_id = $status->id;
				$user = $status->user;
				$date = formatDate($status->created_at);
				$rawdate = formatDate($status->created_at, true);
				$text = formatText($status->text);
				
				$rttext = formatText($status->status->text);
				$rtuser = $status->status->user;
				$rtid = $status->status->id;
			
				$output .= "<li>";
				
				$output .= "
						<span class=\"status_author\">
							<a href=\"user.php?id=$user->screen_name\" target=\"_blank\"><img src=\"$user->profile_image_url\" title=\"$user->screen_name\" /></a>
						</span>
						<span class=\"status_body\">
							<span class=\"status_id\">$status_id</span>
							<span class=\"status_word\"><a class=\"user_name\" href=\"user.php?id=$user->screen_name\" target=\"_blank\">$user->screen_name</a> $text </span>
							"; 
							
				if (isset($status->thumbnail_pic)) {
				$output .= "
				<div class=\"thumb_pic\">
					<a target=\"_blank\" href=\"$status->original_pic\" atl=\"image\">
					<img src=\"$status->thumbnail_pic\">
					</a>
				</div>
				";
				}
				
				$output .= "
						<div class=\"inline_rt\">
							<span class=\"status_body inline_rt_body\">
								<input type=\"hidden\" class=\"rt_id\" value=\"$rtid\" />
								<span class=\"status_word\"><a class=\"user_name\" href=\"user.php?id=$rtuser->screen_name\" target=\"_blank\">@$rtuser->screen_name</a>: $rttext </span>
								
							</span>
							<div class=\"clear\"></div>";
				if (isset($status->retweeted_status->thumbnail_pic)) {
				$output .= "
							<div class=\"thumb_pic\">
								<a target=\"_blank\" href=\"{$status->retweeted_status->original_pic}\" atl=\"image\">
								<img src=\"{$status->retweeted_status->thumbnail_pic}\">
								</a>
							</div>
				";
				}
				$output .= "
						</div>";
				
				
				$output .= "<span class=\"status_info\">
								<a class=\"delete_btn\" href=\"a_del.php?id=$status->id&t=c\">删除</a>
								<span class=\"date\" title=\"$rawdate\"><a href=\"status.php?id=$rtid\" target=\"_blank\">$date</a></span>
							</span>
						</span>";
				$output .= "</li>";
			}
			$output .= "</ol>";
			
			echo $output;
			
				
				$output = "<div id=\"pagination\">";	
				if ($p >1) $output .= "<a href=\"comments.php?t=$type&p=" . ($p-1) . "\">上一页</a>";
				if (!$empty) $output .= "<a href=\"comments.php?t=$type&p=" . ($p+1) . "\">下一页</a>";			
				$output .= "</div>";			
				echo $output;
			}
			
			
			
		?>
	</div>
</div>

<?php 
	include ('inc/sidebar.php');
?>

<?php 
	include ('inc/footer.php');
?>
